package com.mystudy.concurrent.base;

/**
 * TODO:守护线程
 * 可以用来作为心跳连接检测用
 * todo: 线程的优先级
 * 优先级高的线程不一定能保证先执行完
 * @author acy
 * @since 2019/05/10 11:32
 */
public class DeamonThreadTest {
	public static void main(String[] args) {
		threadPriorityTest();
		/*Thread thread = new Thread(() -> {
			try {
				System.out.println(Thread.currentThread().getName()+"running");
				Thread.sleep(5_000);
				System.out.println(Thread.currentThread().getName()+"down");
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		});
		thread.setDaemon(true);
		thread.start();
		System.out.println(Thread.currentThread().getName());*/
	}

	public static void threadPriorityTest(){
		Thread thread = new Thread(() -> {
			for (int i = 0; i < 100; i++) {
				System.out.println("线程1----"+i);
			}
		});
		thread.setPriority(Thread.MAX_PRIORITY);
		Thread thread2 = new Thread(() -> {
			for (int i = 0; i < 100; i++) {
				System.out.println("线程2----"+i);
			}
		});
		thread2.setPriority(Thread.NORM_PRIORITY);
		Thread thread3 = new Thread(() -> {
			for (int i = 0; i < 100; i++) {
				System.out.println("线程3----"+i);
			}
		});
		thread3.setPriority(Thread.MIN_PRIORITY);
		thread.start();
		thread2.start();
		thread3.start();
	}
}
